<template>
    
</template>

<script lang="ts">
// import zpMixins from '@/uni_modules/zp-mixins/index';
// pages/sharePage/sharePage.ts
import { myBillDetails } from '@/api/https'
var marketing_1 = require("../../api/marketing/marketing");
const { reccodeacUserAdd } = marketing_1;
import shareTypes from '../../utils/shareTypes';
const app = getApp();
export default {
    data() {
        return {
            marketingSwitch:app.globalData.marketingSwitch,
            // query参数对象形式
            options: {},
			// 从订单页面复制的变量订单状态
			//val值对应状态:  1 = 充电中  2 = 待支付  3 = 已完成 5 = 账单结算中  其它 = 已关闭
			// state对应值： 1:鉴权成功 2：启动中 3:启动失败 4:充电中 5：充电完成 6:待入库 7:入库失败 8:入库成功 9：费用计算中
			//  10:计费成功 11.待支付 12:支付失败   13:部分支付 14:已结清 15:坏账 16:手动关闭 17:已冲销 18:已退款
			orderStatus: [
				{
					state: '1', 
					val: 1
				},
				{
					state: '2',
					val: 1
				},
				{
					state: '3',
					val: 3
				},
				{
					state: '4',
					val: 1
				},
				{
					state: '5',
					val: 5
				},
				{
					state: '6',
					val: 5
				},
				{
					state: '7',
					val: 5
				},
				{
					state: '8',
					val: 5
				},
				{
					state: '9',
					val: 5
				},
				{
					state: '10',
					val: 2
				},
				{
					state: '11',
					val: 2
				},
				{
					state: '12',
					val: 2
				},
				{
					state: '13',
					val: 2
				},
				{
					state: '14',
					val: 3
				},
				{
					state: '15',
					val: 2
				},
				{
					state: '16',
					val: 4
				},
				{
					state: '17',
					val: 3
				},
				{
					state: '18',
					val: 4
				}
			],
			
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options: any) {
        console.log(options, 'sharepage的options');
        console.log(app.getAppOptions(options), 'sharepage的options');
        this.setData({
            options: app.getAppOptions(options)
        });
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.toSharePage();
    },
    methods: {
        // 去到某个分享页面功能
        toSharePage() {
            app.showLoading();
            let options = this.options;
            let { ST } = this.options;
            let that = this;

            // // 获取query拼到分享链接
            // let query = app.getOptionsQuery(options);

            if (!ST) {
                return;
            }
            if (ST == shareTypes.YAOQING) {
                uni.setStorageSync('inviteType', '1');
                uni.setStorageSync('inviterId', options.uid);
                // 邀请奖励活动id后面8位
                uni.setStorageSync('inviteActivityId', options.HD);
                console.log('执行邀请奖励拉', options);
            }
            if (ST == shareTypes.TUIGUANG) {
                uni.setStorageSync('inviteType', '2');
                uni.setStorageSync('promoterId', options.uid);
                console.log('执行推广奖励啦', options);
                
                // 暂时不跳转绑定页面
                // uni.redirectTo({
                //     url: '/additional/recommend/index' + query
                // });
            }

            // 检查登录状态
            app.globalData.CHECK_LOGIN(async () => {
                // 这里是通过后台生成的二维码进来的10001
                if (ST == shareTypes.ST) {
                    console.log('这里是通过后台生成的二维码进来的', options);
                    let codeacStationId = options.HD;
                    let sellerId = app.globalData.sellerId;
                    reccodeacUserAdd({
                        codeacStationId,
                        sellerId
                    }).then((res: any) => {
                        app.hideLoading();
                        console.log('统计是否成功', res);
                        let data = res.data || {};
                        let { activityId, acTypeId } = data;
                        this.options.HD = activityId;
                        if (res.status == 'B0001') {
                            uni.showModal({
                                title: '提示',
                                content: res.msg || '二维码失效',
                                showCancel: false,
                                success(res: any) {
                                    if (res.confirm) {
                                        that.toDetaile(acTypeId, {
                                            ST: acTypeId,
                                            HD: activityId
                                        });
                                    }
                                }
                            });
                            return;
                        }
                        this.toDetaile(acTypeId, {
                            ST: acTypeId,
                            HD: activityId
                        });
                    });
                    return;
                }
                this.toDetaile(ST, options);
            });
        },

        // 处理跳转逻辑
        toDetaile(ST: string, options: any) {
            // CZJL = "1", //充值奖励详情
            // LJXF = "2", //累计消费详情
            // DBZK = "3", //单笔折扣详情
            // ZDYH = "4", //站点优惠详情
            // YQJL = "5", //邀请奖励详情
            // XKYL = "6", //新客有礼详情
            // DRPT = "7", //多人拼团详情
            app.hideLoading();

            //强制转字符串
            ST = ST + '';
            // 获取query拼到分享链接
            let query = app.getOptionsQuery(options);
            switch (ST) {
				// case shareTypes.TUIGUANG:
				//     console.log('推广1111111111111', options);
				//     uni.redirectTo({
				//         url: '/additional/recommend/index' + query
				//     });
				//     break;
                case shareTypes.PINGTUAN:
                    console.log('执行拼团详情拉', options);
                    uni.redirectTo({
                        url: '/marketing_page/pages/group/detail/index' + query
                    });
                    break;
                case shareTypes.CZJL:
                    uni.redirectTo({
                        url: '/marketing_page/pages/pay/payAward/payAward' + query
                    });
                    break;
                case shareTypes.LJXF:
                    uni.redirectTo({
                        url: '/homeSub/pages/discount/cumulativeMoney/cumulativeMoney' + query
                    });
                    break;
                case shareTypes.DBZK:
                    uni.redirectTo({
                        url: '/homeSub/pages/discount/singleMoney/singleMoney' + query
                    });
                    break;
                case shareTypes.ZDYH:
                    uni.redirectTo({
                        url: '/homeSub/pages/discount/siteOffers/siteOffers' + query
                    });
                    break;
                case shareTypes.YQJL:
                    uni.redirectTo({
                        url: '/marketing_page/pages/invite/invitation/invitation' + query
                    });
                    break;
                case shareTypes.DRPT:
                    let HD = this.options.HD;
                    // 特殊情况手动拼链接
                    uni.redirectTo({
                        url: `/marketing_page/pages/group/detail/index?activityId=${HD}&groupId=null`
                    });
                    break;
				
				case shareTypes.ZFF:
					console.log(this.options,'支付分卡片进入')
					let { order:id } = this.options
					myBillDetails({id}).then(res=>{
						console.log(res,'订单详情获取')
						if(res.code == 0){
							console.log(res.data.billStatus)
							let billStatus = res.data.billStatus
							let busId = res.data.busId
							
							
							let type = this.orderStatus.find(item => item.state == billStatus).val
							console.log(type)
							if(type == 5){
								uni.redirectTo({
									url: '/orderSub/pages/orderInSettlement/orderInSettlement?orderId=' + id
								});
							}else{
                                if (!this.marketingSwitch) {
						                uni.redirectTo({
						                	url: '/orderSub/pages/orderDetails/orderDetails?orderId=' + id + '&type=' + type
						                });
					                    } else {
						                uni.redirectTo({
							                url: '/orderSub/pages/orderDetailsYxhk/orderDetailsYxhk?orderId=' + id + '&type=' + type
						                });
					                    }
								// uni.redirectTo({
								// 	url: '/orderSub/pages/orderDetails/orderDetails?orderId=' + id + '&type=' + type
								// });
							}
						}else{
							uni.reLaunch({
								url: '/pages/index/index'
							});
						}
					})
					break;
				case shareTypes.SAOMA:
					console.log('跳转的路径',`/mine/pages/couponCenter/detail?id=${this.options.HD}`)
				    uni.redirectTo({
				        url: `/mine/pages/couponCenter/detail?id=${this.options.HD}`
				    });
				    break;
                default:
                    uni.reLaunch({
                        url: '/pages/index/index'
                    });
            }
        }
    }
};
</script>
<style lang="less">
/* pages/sharePage/sharePage.wxss */
</style>
